import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:vape_xe/routes/app_pages.dart';
import 'package:vape_xe/services/services.dart';
import 'package:vape_xe/utils/utils.dart';

import 'logic.dart';

class WithdrawAddressView extends GetView<WithdrawAddressController> {
  const WithdrawAddressView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios_new_rounded),
          onPressed: () => Get.back(),
        ),
        title: Text('Account'.tr),
        actions: [
          if (Get.arguments['type'] == 3) //DuitNow
            TextButton(
              onPressed: () => Get.toNamed(
                Routes.WEB_VIEW,
                arguments: {'url': ConfigStore.to.webUrls['Case of DuitNow']},
              ),
              child: Text(
                'Case'.tr,
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18.sp, color: Colors.white), // 设置文字颜色
              ),
            ),
          SizedBox(width: 8.w),
        ],
      ),
      body: Column(
        mainAxisSize: MainAxisSize.max,
        children: [
          Expanded(
            child: Obx(
              () => controller.addressList.isEmpty
                  ? Center(child: Text('No address'.tr))
                  : ListView.builder(
                      itemCount: controller.addressList.length,
                      shrinkWrap: true, // 防止 ListView 自身滚动
                      physics: const NeverScrollableScrollPhysics(), // 禁止 ListView 自身滚动
                      itemBuilder: (context, index) => GestureDetector(
                        onTap: () => controller.onTap(index),
                        child: Container(
                          height: 64.h,
                          margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 7.h),
                          decoration: BoxDecoration(color: Colors.white10, borderRadius: 12.radius),
                          child: Row(
                            children: [
                              16.vGap,
                              Image.asset(
                                  controller.addressList[index]['type'] == 3
                                      ? 'assets/images/ic_duitnow.webp'
                                      : 'assets/images/ic_usdt.webp',
                                  width: 28.w,
                                  height: 28.w),
                              12.vGap,
                              Expanded(
                                child: Text(
                                  controller.addressList[index]['uniqueId'],
                                  style: TextStyle(fontSize: 12.sp, fontFamily: 'Montserrat'),
                                ),
                              ),
                              12.vGap,
                            ],
                          ),
                        ),
                      ),
                    ),
            ),
          ),
          16.hGap,
          GestureDetector(
            onTap: () => controller.newAddress(),
            child: Container(
              height: 52.h,
              margin: EdgeInsets.all(32.w),
              alignment: Alignment.center,
              decoration: BoxDecoration(borderRadius: 16.radius, color: Colors.white10),
              child: Text(
                'Add address'.tr,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontFamily: 'Montserrat',
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
          16.hGap,
        ],
      ),
    );
  }
}
